home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / libsrc / mm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.4 KB  |  100 lines

  1. /* This is file mm.c */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include <dir.h>
  19. #include <dos.h>
  20.  
  21. main()
  22. {
  23.   FILE *fin, *fout;
  24.   char buf[200];
  25.   fin = fopen("maketmpl", "r");
  26.   fout = fopen("makefile.n", "w");
  27.   fprintf(fout, "# This file is generated from maketmpl by mm.c\n");
  28.   while (fgets(buf, 200, fin) != NULL)
  29.   {
  30.     if (strncmp(buf, "@dir ", 5) == 0)
  31.       handle_dir(fout, buf+5);
  32.     else if (strncmp(buf, "@dir2 ", 6) == 0)
  33.       handle_dir2(fout, buf+6);
  34.     else
  35.       fputs(buf, fout);
  36.   }
  37.   fclose(fin);
  38.   fclose(fout);
  39. }
  40.  
  41. handle_dir(FILE *f, char *line)
  42. {
  43.   char fname[100];
  44.   sscanf(line, "%s", fname);
  45.   handle_wild(f, fname, "*.c");
  46.   handle_wild(f, fname, "*.cc");
  47.   handle_wild(f, fname, "*.S");
  48. }
  49.  
  50. handle_wild(FILE *f, char *dir, char *wild)
  51. {
  52.   struct ffblk ff;
  53.   char buf[100], *cp;
  54.   int done;
  55.   sprintf(buf, "%s/%s", dir, wild);
  56.   done = findfirst(buf, &ff, FA_ARCH | FA_RDONLY);
  57.   while (!done)
  58.   {
  59.     fputs("\t$(ODIR)/", f);
  60.     sprintf(buf, "%s", ff.ff_name);
  61.     strlwr(buf);
  62.     cp = strrchr(buf, '.');
  63.     strcpy(cp, ".o \\\n");
  64.     fputs(buf, f);
  65.     done = findnext(&ff);
  66.   }
  67. }
  68.  
  69. handle_dir2(FILE *f, char *line)
  70. {
  71.   char fname[100];
  72.   sscanf(line, "%s", fname);
  73.   handle_wild2(f, fname, "*.c");
  74.   handle_wild2(f, fname, "*.cc");
  75.   handle_wild2(f, fname, "*.S");
  76. }
  77.  
  78. handle_wild2(FILE *f, char *dir, char *wild)
  79. {
  80.   struct ffblk ff;
  81.   char buf[100], *cp;
  82.   int done;
  83.   sprintf(buf, "%s/%s", dir, wild);
  84.   done = findfirst(buf, &ff, FA_ARCH | FA_RDONLY);
  85.   while (!done)
  86.   {
  87.     strcpy(buf, ff.ff_name);
  88.     strlwr(buf);
  89.     cp = strrchr(buf, '.');
  90.     *cp = 0;
  91.  
  92.     fprintf(f, "$(ODIR)/%s.o : %s/%s%s\n", buf, dir, buf, wild+1);
  93.     fprintf(f, "\tgcc $(PG) $(CFLAGS) -c %s/%s%s -o $(ODIR)/%s.o\n",
  94.         dir, buf, wild+1, buf);
  95.     fprintf(f, "\n");
  96.  
  97.     done = findnext(&ff);
  98.   }
  99. }
  100.